import os
import h5py
import cv2

def show_hdf5_structure(dataset_path):
    """
    显示HDF5文件的内部结构和数据格式
    Args:
        dataset_path: HDF5文件路径
    """
    def print_attrs(name, obj):
        print(f"\n{name}:")
        # 打印数据集的属性
        if len(obj.attrs) > 0:
            print("  Attributes:")
            for key, value in obj.attrs.items():
                print(f"    {key}: {value}")
        # 如果是数据集,打印形状和数据类型
        if isinstance(obj, h5py.Dataset):
            print(f"  Shape: {obj.shape}")
            print(f"  Dtype: {obj.dtype}")

    print(f"\nHDF5文件结构 ({dataset_path}):")
    print("=" * 50)
    
    with h5py.File(dataset_path, 'r') as f:
        # 打印文件级别的属性
        if len(f.attrs) > 0:
            print("文件属性:")
            for key, value in f.attrs.items():
                print(f"  {key}: {value}")
        
        # 递归访问所有组和数据集
        f.visititems(print_attrs)

if __name__ == "__main__":
    show_hdf5_structure("/home/rm/engineering-imitation-learning/data/aloha_mobile_dummy/episode_0.hdf5")